//
//  LGDiseaseMedicinDateCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/16.
//

#import "LGDiseaseMedicineDateCell.h"

@interface LGDiseaseMedicineDateCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;

@end

@implementation LGDiseaseMedicineDateCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    CGFloat topMargin = 0;
    if(dataDic.allKeys.count>0){
        NSString *type = LGNSString(dataDic[@"source_type"]);
        self.tipLabel.text = LGNSString(dataDic[@"source"]);
        if([type isEqualToString:@"advice"]){
            //用药方案
            topMargin = viewPix(12);
            self.titleLabel.hidden = YES;
            self.checkBtn.hidden = YES;
            if([dataDic[@"source"] isEqualToString:@"出院医嘱"]){
                self.tipLabel.hidden = NO;
                self.dateLabel.text = LGNSString(dataDic[@"advice_date"]);
            }else{
                self.tipLabel.hidden = YES;
                self.dateLabel.text = [NSString stringWithFormat:@"%@  %@",dataDic[@"advice_date"],dataDic[@"doctor_name"]];
            }
        }else{
            //用药记录
            topMargin = viewPix(45);
            self.titleLabel.hidden = NO;
            self.checkBtn.hidden = NO;
            self.tipLabel.hidden = YES;
            self.dateLabel.text = LGNSString(dataDic[@"advice_date"]);
        }
    }
    [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(topMargin);
    }];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.checkBtn];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.tipLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.top.bottom.equalTo(self.contentView);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(15));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.bottom.equalTo(self.baseView).offset(-viewPix(5));
        make.width.equalTo(@(4));
        make.height.equalTo(@(viewPix(14)));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView.mas_right).offset(viewPix(3));
        make.centerY.equalTo(self.lineView);
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dateLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.lineView);
        make.width.equalTo(@(viewPix(56)));
        make.height.equalTo(@(viewPix(18)));
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"医助采集" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(12), 0, viewPix(150), viewPix(40));
        _titleLabel.hidden = YES;
    }
    return _titleLabel;
}


-(UIButton *)checkBtn{
    if(!_checkBtn){
        _checkBtn = [UIButton buttonWithTitle:@"查看全部" titleFont:LGFont(14) textColor:@"#666666" imageName:@"grayTip12"];
        _checkBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _checkBtn.frame = CGRectMake(0, 0, Screen_W-viewPix(44), viewPix(40));
        [_checkBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
        _checkBtn.hidden = YES;
    }
    return _checkBtn;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#77D4C6"];
        _lineView.cornerRidus = 2;
    }
    return _lineView;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(10, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _tipLabel.backgroundColor = [UIColor colorWithString:@"#EAF4FF"];
        _tipLabel.cornerRidus = viewPix(9);
        _tipLabel.hidden = YES;
    }
    return _tipLabel;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
